package panel.downloadZipPanel
{
	import assists.Lang;
	import assists.URI;
	import assists.resource.ResourceLoader;
	
	import com.greensock.TweenLite;
	
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.utils.setTimeout;
	
	import inerface.IDownloadZipPanel;
	
	import main.ClientConstants;
	
	public class DownloadZipPanel extends Sprite implements IDownloadZipPanel
	{
		private var _stage:Stage;
		private var _loader:ResourceLoader;
		private var _lang:Lang;
		private var _uri:URI;
		
		private var page1:ResourceListPage;
		private var page2:ResourceListPage;
		
		private var infoList:Array;
		
		private var chooseThisCity:Function;
		
		public function DownloadZipPanel()
		{
			infoList = [];
		}
		
		public function init(stage:Stage, loader:ResourceLoader, lang:Lang, uri:URI=null):void
		{
			_stage = stage;
			_loader = loader;
			_lang = lang;
			_uri = uri;
			
			page1 = new ResourceListPage(_stage,_loader,_lang,_uri);
			page1.onShowDetail = showScenicList;
			page2 = new ResourceListPage(_stage,_loader,_lang,_uri);
			page2.backToCtiy = backToCity;
			
			this.addChild(page1);
			page1.x = 0;
			page1.y = _stage.stageHeight * ClientConstants.HOME_UP_PER;
			
			this.addChild(page2);
			page2.x = _stage.stageWidth;
			page2.y= _stage.stageHeight * ClientConstants.HOME_UP_PER;
		}
		
		public function changeData(list:Array):void
		{
			infoList = list;
			page1.onChooseCity = chooseThisCity;
			page1.changeData(list,1);
		}
		
		private function showScenicList(id:int,has:Boolean):void
		{
			var obj:Object = new Object;
			for(var i:int = 0;i < infoList.length;i++){
				if(infoList[i].id == id){
					obj = infoList[i];
				}
			}
			
			page2.hasZip = has;
			page2.changeData(obj.scenicList,2);
			TweenLite.to(page1,.5,{x:-_stage.stageWidth});
			TweenLite.to(page2,.5,{x:0});
		}
		
		private function backToCity():void
		{
			TweenLite.to(page1,.5,{x:0});
			TweenLite.to(page2,.5,{x:_stage.stageWidth});
		}
		
		public function set onChooseCity(func:Function):void
		{
			chooseThisCity = func;
		}
		
		public function clear():void
		{
			if(_stage){
				_stage = null;
				_loader = null;
				_lang = null;
				_uri = null;
				
				page1.clear();
				page2.clear();
			}
		}
	}
}